home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / syssignal.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-15  |  7.5 KB  |  228 lines

  1. /* syssignal.h - System-dependent definitions for signals.
  2.    Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: FSF 19.28. */
  21.  
  22. #ifndef _XEMACS_SYSSIGNAL_H_
  23. #define _XEMACS_SYSSIGNAL_H_
  24.  
  25. /* In the old world, one could not #include <signal.h> here.  The party line
  26.    was that that header should always be #included before <config.h>, because
  27.    some configuration files (like s/hpux.h) indicate that SIGIO doesn't work
  28.    by #undef-ing SIGIO, and if this file #includes <signal.h>, then that will
  29.    re-#define SIGIO and confuse things.
  30.  
  31.    This was, however, a completely fucked up state of affairs, because on some
  32.    systems it's necessary for the s/m files to #define things in order to get
  33.    <signal.h> to provide the right typedefs, etc.  And it's generally a broken
  34.    concept for <config.h> to not be the very very first file included.
  35.  
  36.    So instead of #undef'ing SIGIO in the various s/m files, I've changed them
  37.    to define BROKEN_SIGIO instead, then we (syssignal.h) do an #undef SIGIO
  38.    at the end, after including signal.h.  Therefore, it's important that
  39.    <signal.h> not be included after "syssignal.h", but that's the normal state:
  40.    nothing should be directly including <signal.h> these days.
  41.                             -- jwz, 29-nov-93
  42.  */
  43.  
  44. #include <signal.h>
  45. #include <errno.h>
  46.  
  47. /* SIGPOLL is the SVR4 signal.  Those systems generally define
  48.    SIGIO as an alias for SIGPOLL, but just in case ... */
  49.  
  50. #if !defined (SIGIO) && defined (SIGPOLL)
  51. # define SIGIO SIGPOLL
  52. #endif
  53.  
  54. #if defined (BROKEN_SIGIO)
  55. # undef SIGIO
  56. #endif
  57.  
  58. /* Define SIGCHLD as an alias for SIGCLD.  There are many conditionals
  59.    testing SIGCHLD.  */
  60. #if !defined (VMS) && defined (SIGCLD) && !defined (SIGCHLD)
  61. # define SIGCHLD SIGCLD
  62. #endif /* SIGCHLD */
  63.  
  64. #ifdef BROKEN_SIGCHLD
  65. #undef SIGCHLD
  66. #endif
  67.  
  68. #ifdef SIGCHLD
  69. #define EMACS_BLOCK_SIGCHLD EMACS_BLOCK_SIGNAL (SIGCHLD)
  70. #define EMACS_UNBLOCK_SIGCHLD EMACS_UNBLOCK_SIGNAL (SIGCHLD)
  71. #else
  72. #define EMACS_BLOCK_SIGCHLD
  73. #define EMACS_UNBLOCK_SIGCHLD
  74. #endif
  75.  
  76. /* According to W.R. Stevens __Advanced Programming in the Unix
  77.    Environment__, there are four different paradigms for handling
  78.    signals.  We use autoconf to tell us which one applies.
  79.  
  80.    Note that on some systems, more than one paradigm is implemented
  81.    (typically, the POSIX sigaction/sigprocmask and either the older
  82.    SYSV or BSD way).  In such a case, we prefer the POSIX way.
  83.  
  84.    NOTE: We use EMACS_* macros for most signal operations, but
  85.    just signal() for the standard signal-setting operation.
  86.    Perhaps we should change this to EMACS_SIGNAL(), but that runs
  87.    the risk of someone forgetting this convention and calling
  88.    signal() directly. */
  89.  
  90. #if defined (HAVE_SIGPROCMASK)
  91.  
  92. /* The POSIX way (sigaction, sigprocmask, sigpending, sigsuspend) */
  93.  
  94. typedef SIGTYPE (*signal_handler_t) (int);
  95. extern signal_handler_t sys_do_signal (int signal_number,
  96.                        signal_handler_t action);
  97. /* Provide our own version of signal(), that calls sigaction().  The
  98.    name is not sys_signal() because a function of that name exists in
  99.    libenergize.a */
  100. #define signal sys_do_signal
  101.  
  102. #define EMACS_BLOCK_SIGNAL(sig) do        \
  103. {                        \
  104.   sigset_t _mask;                \
  105.   sigemptyset (&_mask);                \
  106.   sigaddset (&_mask, sig);            \
  107.   sigprocmask (SIG_BLOCK, &_mask, NULL);    \
  108. } while (0)
  109. #define EMACS_UNBLOCK_SIGNAL(sig) do        \
  110. {                        \
  111.   sigset_t _mask;                \
  112.   sigemptyset (&_mask);                \
  113.   sigaddset (&_mask, sig);            \
  114.   sigprocmask (SIG_UNBLOCK, &_mask, NULL);    \
  115. } while (0)
  116. #define EMACS_UNBLOCK_ALL_SIGNALS() do        \
  117. {                        \
  118.   sigset_t _mask;                \
  119.   sigemptyset (&_mask);                \
  120.   sigprocmask (SIG_SETMASK, &_mask, NULL);    \
  121. } while (0)
  122. #define EMACS_WAIT_FOR_SIGNAL(sig) do        \
  123. {                        \
  124.   sigset_t _mask;                \
  125.   sigprocmask (0, NULL, &_mask);        \
  126.   sigdelset (&_mask, sig);            \
  127.   sigsuspend (&_mask);                \
  128. } while (0)
  129. #define EMACS_REESTABLISH_SIGNAL(sig, handler)
  130.   
  131. #elif defined (HAVE_SIGBLOCK)
  132.  
  133. /* The older BSD way (signal/sigvec, sigblock, sigsetmask, sigpause) */
  134.  
  135. /* It's OK to use signal() here directly.  No unreliable signal
  136.    problems.  However, we use sigvec() because it allows us to
  137.    request interruptible I/O. */
  138.  
  139. #define signal sys_do_signal
  140.  
  141. /* Is it necessary to define sigmask like this? */
  142. #ifndef sigmask
  143. # define sigmask(no) (1L << ((no) - 1))
  144. #endif
  145.  
  146. #define EMACS_BLOCK_SIGNAL(sig) sigblock (sigmask (sig))
  147. #define EMACS_UNBLOCK_SIGNAL(sig) sigsetmask (sigblock (0) & ~sigmask (sig))
  148. #define EMACS_UNBLOCK_ALL_SIGNALS() sigsetmask (0)
  149. #define EMACS_WAIT_FOR_SIGNAL(sig) do        \
  150. {                        \
  151.   int _mask = sigblock (0);            \
  152.   sigpause (_mask & ~sigmask (sig));        \
  153. } while (0)
  154. #define EMACS_REESTABLISH_SIGNAL(sig, handler)
  155.  
  156. #elif defined (HAVE_SIGHOLD)
  157.  
  158. /* The older SYSV way (signal/sigset, sighold, sigrelse, sigignore,
  159.    sigpause) */
  160.  
  161. #define signal sigset
  162. #define EMACS_BLOCK_SIGNAL(sig) sighold (sig)
  163. #define EMACS_UNBLOCK_SIGNAL(sig) sigrelse (sig)
  164. /* #### There's not really any simple way to implement this.
  165.    Since EMACS_UNBLOCK_ALL_SIGNALS() is only called once (at startup),
  166.    it's probably OK to just ignore it. */
  167. #define EMACS_UNBLOCK_ALL_SIGNALS() 0
  168. #define EMACS_WAIT_FOR_SIGNAL(sig) sigpause (sig)
  169. #define EMACS_REESTABLISH_SIGNAL(sig, handler)
  170.  
  171. #else
  172.  
  173. /* The oldest SYSV way (signal only; unreliable signals) */
  174.  
  175. /* Old USG systems don't really have signal blocking.
  176.    We indicate this by not defining EMACS_BLOCK_SIGNAL or
  177.    EMACS_WAIT_FOR_SIGNAL. */
  178. #define EMACS_UNBLOCK_SIGNAL(sig) 0
  179. #define EMACS_UNBLOCK_ALL_SIGNALS() 0
  180. #define EMACS_REESTABLISH_SIGNAL(sig, handler) do    \
  181. {                            \
  182.   int old_errno = errno;                \
  183.   signal (sig, handler);                \
  184.   errno = old_errno;                    \
  185. } while (0)
  186.  
  187. /* Under SYSV, setting a signal handler for SIGCLD causes
  188.    SIGCLD to immediately be sent if there any unwaited processes
  189.    out there.  This means that the SIGCLD handler *must* call
  190.    wait() to reap the status of all processes -- it cannot
  191.    simply set a flag and then reestablish the handler, because
  192.    it will get called again, infinitely.  We only need to
  193.    worry about this on systems where signals need to be
  194.    reestablished (SYSV Release 2 and earlier). */
  195. #define OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
  196.  
  197. #endif
  198.  
  199. /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
  200.    Must do that using the killpg call.  */
  201. #ifdef BSD
  202. #define EMACS_KILLPG(gid, signo) killpg (gid, signo)
  203. #else
  204. #define EMACS_KILLPG(gid, signo) kill (-(gid), signo)
  205. #endif
  206.  
  207. #ifdef VMS
  208. # define sys_siglist sys_errlist
  209. # define NSIG sys_nerr
  210. #endif /* VMS */
  211.  
  212. #ifndef NSIG
  213. # define NSIG (SIGUSR2+1) /* guess how many elements are in sys_siglist... */
  214. #endif
  215.  
  216. /* SYS_SIGLIST_DECLARED is determined by configure.  On Linux, it seems,
  217.    configure incorrectly fails to find it, so s/linux.h defines
  218.    HAVE_SYS_SIGLIST. */
  219. #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
  220. extern CONST char *sys_siglist[];
  221. #endif
  222.  
  223. #ifdef SIGDANGER
  224. extern SIGTYPE memory_warning_signal (int sig);
  225. #endif
  226.  
  227. #endif /* _XEMACS_SYSSIGNAL_H_ */
  228.